home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / p2c.zip / DOALLOC.C next >
C/C++ Source or Header  |  1987-03-27  |  709b  |  38 lines

  1. /* doalloc.c: memory allocations which exit upon error */
  2.  
  3. #include <stdio.h>
  4. #ifndef NULL
  5. #define NULL ((char *) 0)
  6. #endif
  7.  
  8. /* act like calloc, but return only if no error */
  9. char *DoRealloc(ptr,size)
  10.     char *ptr;
  11.     unsigned size;
  12. {
  13.     extern char *realloc();
  14.     char *p;
  15.  
  16.     if ((p=realloc(ptr, size)) == NULL) {
  17.     fprintf(stderr, "memory allocation (realloc) error");
  18.     exit(1);
  19.     }
  20.     return (p);
  21. }
  22.  
  23.  
  24. /* act like malloc, but return only if no error */
  25. char *DoMalloc(size)
  26.     unsigned size;
  27. {
  28.     extern char *malloc();
  29.     char *p;
  30.  
  31.     if ((p=malloc(size)) == NULL) {
  32.     fprintf(stderr, "memory allocation (malloc) error");
  33.     exit(1);
  34.     }
  35.     return (p);
  36. }
  37.  
  38.